package com.trainbook.utils.sort;

import com.trainbook.entity.VO.TrainVO;

import java.util.Comparator;
import java.util.List;

/**
 * @Author: Dempsey
 * @Date: 2020/12/25 19:53
 * @Description:
 */
public class TrainVOComparator implements Comparator<TrainVO> {

    @Override
    public int compare(TrainVO o1, TrainVO o2) {

        // 排序优先级依次为，少换乘，少时间，少价格
        int cmp = (o1.getTrainNameMap().size() - o2.getTrainNameMap().size());
        if (cmp == 0) {
            List<Long> takeTime1 = o1.getTakeTime();
            List<Long> takeTime2 = o2.getTakeTime();
            cmp = (int) (takeTime1.get(0) - takeTime2.get(0));
            if (cmp == 0) {
                cmp = (int) (takeTime1.get(1) - takeTime2.get(1));
                if (cmp == 0) {
                    cmp = (int) (takeTime1.get(2) - takeTime2.get(2));
                    if (cmp == 0) {
                        cmp = (int) (takeTime1.get(3) - takeTime2.get(3));
                        if (cmp == 0) {
                            cmp = (int) (o1.getPrice() - o2.getPrice());
                        }
                    }
                }
            }
        }
        return cmp;
    }

}
